n = 0: 20;

a_1_1 = [3, 4, 1];
b_1_1 = [1, 1];
x_1_1 = (n == 0);
y_1_1 = filter(b_1_1, a_1_1, x_1_1);

a_1_2 = [5 / 2, 6, 10];
b_1_2 = [1];
x_1_2 = (n == 0);
y_1_2 = filter(b_1_2, a_1_2, x_1_2);

n_2 = 0:40;
h_1 = ((7 / 8) .^ n)  .* (uDT(n) - uDT(n - 10));
x_2 = uDT(n) - uDT(n - 5);
y_2 = conv(x_2, h_1);

figure(1);
subplot(3, 1, 1);
stem(n, y_1_1);
xlabel("n");
title("(1)1)");

subplot(3, 1, 2);
stem(n, y_1_2);
xlabel("n");
title("(1)2)");

subplot(3, 1, 3);
stem(n_2, y_2);
xlabel("n");
title("(2)");

figure(2);
a_3 = [3, 4, 1];
b_3 = [1, 1];
y = impz(b_3, a_3, 20);
impz(b_3, a_3, 20);
title("(1)1) 库函数版");

figure(3);
a_4 = [5 / 2, 6, 10];
b_4 = [1];
y_4 = impz(b_4, a_4, 20);
impz(b_4, a_4, 20);
title("(1)2) 库函数版");

figure(4);
Gx=[-1 0 1;-2 0 2;-1 0 1];
Gy=[1 2 1;0 0 0;-1 -2 -1];

B = imread('lena.bmp');

C_1 = conv2(Gx, B);
C_2 = conv2(Gy, B);
C_3 = conv2(Gx, C_1);
subplot(2, 2, 1);
imshow(B);
title("原图");

subplot(2, 2, 2);
imshow(C_1);
title("Gx卷积");

subplot(2, 2, 3);
imshow(C_2);
title("Gy卷积");

subplot(2, 2, 4);
imshow(C_3);
title("先Gx再Gy卷积");
